import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/modules/preferences/api/preferencesApi.dart';
import 'package:honeypotflutter/public/public_get.dart';
import 'package:honeypotflutter/public/public_alert.dart';
import 'package:honeypotflutter/public/public_total.dart';

class PreferencesAddLogic extends GetxController {
  /// 手机号
  TextEditingController phone = TextEditingController();

  /// 偏好设置
  TextEditingController preference = TextEditingController();

  /*
  * 弹框
  * */
  sheetBottom() {
    HLAlert.showSheet(
        title: "请选择",
        menuList: ["该用户偏好上门", "该用户需要电话联系", "该用户需要短信取件码"],
        action: (int index, String text) {
          preference.text = text;
        });
  }

  /*
  * 确认按钮
  * */
  sureAction() async {
    if (!GetUtils.isPhoneNumber(phone.text)) {
      HLTotal.total("请输入正确手机号码");
      return;
    }
    if (preference.text.isEmpty) {
      HLTotal.total("请选择偏好设置");
      return;
    }

    PreferencesApi.addPreferences(phone.text, preference.text).then((value) {
      HLGet.back(result: true);
    });
  }
}
